<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组的API</title>
</head>

<body>
    <script>
        /* var arr = [1, 2, 3, 4, 5, 6];
        console.log(arr.slice(0, 3)); // Array 输出一个新数组 [1, 2, 3]
        console.log(arr.slice(0)); // [1, 2, 3, 4, 5, 6] 输出一个新数组 */

        /* let arr = [1, 2, 3, 4]
        let arr2 = arr.keys();
        console.log(arr2);
        for (let key of arr2) {
            console.log(key); // 0,1,2,3
        } */

        /* //eg:1
        let arr = ['js', 'java', 'jquery'];
        let newarr = arr.filter(x => console.log(x)); //js java jquery   返回一个空数组
        console.log(newarr);

        //eg:2
        a = [5, 4, 3, 2, 1];
        values = a.filter(function (x) {
            return x < 3
        }); // [2,1]
        console.log(values); */

        /* let arr = ['js', 'java', , 'jquery'];
        for (var i = 0; i < arr.length; i++) {
            console.log(arr[i]);
        }
        arr.forEach(item => {
            console.log(item);
        }) */

        /* var arr = [1, [2, [[3, 4], 5], 6]];
        var newArr = [];

        function fun(arr) {
            for (var i = 0; i < arr.length; i++) {
                if (Array.isArray(arr[i])) {
                    fun(arr[i]);
                } else {
                    newArr.push(arr[i]);
                }
            }
        }
        fun(arr);
        console.log(newArr); //[1, 2, 3, 4, 5, 6] */

        /* var arr = [1, [2, [[3, 4], 5], 6]];
        var arr2 = arr.join(',').split(',');
        console.log(arr.join(','));
        console.log(arr2); //["1", "2", "3", "4", "5", "6"]

        var c=[1,3,4,5,[6,[0,1,5],9],[2,5,[1,5]],[5]];
        console.log(c.toString().split(',')) */

        const arr = [1,[2,3],[4,5]];
        console.log([].concat.apply([],arr));// apply([],arr)) ==> concat(1,[1,3],[4,5]) ==> [].concat(arr) ==> [].concat([1,[2,3],[4,5]]) 这样是错的，所以要用 apply
        console.log([].concat(1,[1,3],[4,5]))
    </script>
</body>

</html>